package cn.itsource.basic.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

@Component
public class EmailUtils {

    @Autowired
    private JavaMailSender mailSender;

    public  void sendEmail(String emailAddress,Long id) {
        try {
            //发送复杂邮件
            MimeMessage mimeMessage = mailSender.createMimeMessage();
            //发送复杂邮件的工具类
            MimeMessageHelper helper = new MimeMessageHelper(mimeMessage,true,"utf-8");
            //设置发件人
            helper.setFrom("64009120@qq.com");
            //收件人
            helper.setTo(emailAddress);
            //设置主题
            helper.setSubject("宠物之间审核通知");


            helper.setText("<h2>您的店铺审核已通过，点击下方链接就可以登录系统做业务了</h2><br><br><br><br><br><a href='http://127.0.0.1:80/emp/email/"+id+"'>点击激活管理员账号</a>",true);


            mailSender.send(mimeMessage);
        } catch (MessagingException e) {
            e.printStackTrace();
        }
    }
}
